#!/usr/local/bin/python2.7

import sys
import math
import io

class CEvaluater:
	def __init__(self):
		self.note_lst=[0,0.5,1,1.5,2,2.5,3]
		pass
	def test_distribute(self, test):
		for i in range(len(test)):
			abs_sub=[0,0,0,0,0,0,0]
			for j in range(len(abs_sub)):
				abs_sub[j]=math.fabs(self.note_lst[j] - test[i])

			min_val=abs_sub[0]
			min_idx=0
			for j in range(len(abs_sub)):
				if abs_sub[j] < min_val:
					min_val = abs_sub[j]
					min_idx = self.note_lst[j]
			print "%f\t%f"%(test[i],min_idx)
		return

	def differece_compare(self, base, test):
		val_map={}
		for i in range(len(base)):
			if base[i] in val_map:
				val_map[base[i]].append(test[i])
			else:
				val_map[base[i]]=[test[i]]

		lst_score = [ [x[0], len(x[1])] for x in val_map.items()]
		lst_score = sorted(lst_score, key=lambda x:x[0]);
		for i in lst_score:
			print "%f\t%d\t"%(i[0], i[1])

		return

	def comp_MSE(self, base, test, mse):
		if len(base) != len(test):
			print "Error: length of both are not equal"
			return -1
		else:
			mse = 0.0
			mean = 0.0
			delta = 0.0
			for i in range(len(base)):
				mean = mean + (test[i] - base[i])
				mse = mse + (test[i] - base[i])*(test[i] - base[i])
			mse = mse / len(base)
			mse = math.sqrt(mse)

			mean = mean /len(base)

			for i in range(len(base)):
				delta = delta + ((test[i] - base[i]) - mean)*((test[i] - base[i]) - mean)

			delta = delta/len(base)
			delta = math.sqrt(delta)
			print "mse:%f"%(mse)
			print "mean:%f"%(mean)
			print "delta:%f"%(delta)
		return 0

	def comp_pearson(self, base, test, invalid):

		min_len = len(base)
		if len(test) < min_len:
			min_len = len(test)

		print "com_len:%d"%(min_len);
		#sumX = reduce(lambda x,y:x+y, base);
		#sumY = reduce(lambda x,y:x+y, test);

		#sumX_square = reduce(lambda x,y:x*x+y*y, base);
		sumX = 0.0
		sumX_square = 0.0
		for i in range(len(base)):
			sumX += base[i]
			sumX_square += base[i]*base[i]
		print "sumX: %f"%(sumX);
		print "sumX_square: %f"%(sumX_square);

		#sumY_square = reduce(lambda x,y:x*x+y*y, test);
		sumY = 0.0
		sumY_square = 0.0
		for i in range(len(test)):
			sumY += test[i]
			sumY_square += test[i]*test[i]
		print "sumY: %f"%(sumY);
		print "sumY_square: %f"%(sumY_square);

		sumProduct = reduce(lambda x,y:x+y, [base[i]*test[i] for i in range(min_len)])

		print "sumProduct: %f"%(sumProduct);
		top = sumProduct - (sumX*sumY/min_len);
		bottom = math.sqrt( (sumX_square - sumX*sumX/min_len) * (sumY_square - sumY*sumY/min_len) );

		if bottom == 0:
			return 0
		else:
			return top/bottom

	def comp_MAE(self, base, test, mae):
		if len(base) != len(test):
			print "Error: length of both are not equal"
			return -1
		else:
			mae = 0.0
			mean = 0.0
			for i in range(len(base)):
				mae = mae + math.fabs(test[i] - base[i])
			mae = mae / len(base);
			print "mae:%f"%(mae)
		return 0

if __name__ == "__main__":
	eval = CEvaluater()
	test=[]
	base=[]

#	f = open(sys.argv[1], "r")

	for line in sys.stdin.readlines():
		line = line.strip("\r\n")
		if line[0] == '#': continue;
		pair = line.split("\t")
		base.append( float(pair[0]) )
		test.append( float(pair[1]) )

	mse = 0.0
	mae = 0.0
	eval.differece_compare(base, test)
	print "Pearson relevance: %f"%(eval.comp_pearson(base, test, -1.0))
	eval.comp_MSE(base, test, mse)
	eval.comp_MAE(base, test, mae)
#	eval.test_distribute(test)

